﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Microsoft.SharePoint.Administration;
using System.Windows;

namespace SharePointCommander.Model.TreeView
{
    class SCServiceApplicationCollection : SCTreeViewItem<SPServiceApplicationCollection>
    {
        public SCServiceApplicationCollection(SCTreeViewItem parent, SPServiceApplicationCollection applications)
            : base(parent, applications)
        {
            Header = "Applications";
            IsExpanded = false;
            Expanded += new RoutedEventHandler(SCServiceApplicationCollection_Expanded);
            ItemsSource = new object[] { null };
        }

        void SCServiceApplicationCollection_Expanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem item = e.Source as TreeViewItem;
            if (!item.ItemsSource.OfType<SCServiceApplication>().Any())
            {
                item.ItemsSource = from s in SPObject select new SCServiceApplication(this, s) as TreeViewItem;
            }
        }
    }
}
